﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Security.AccessControl;
namespace NFinalCompiler.Sql.SQLite
{
    public class CopyFiles
    {
        public static bool Copy()
        {
            try
            {
                string x64Path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "x64");
                string x64FileName = Path.Combine(x64Path, "SQLite.Interop.dll");
                string x86Path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "x86");
                string x86FileName = Path.Combine(x86Path, "SQLite.Interop.dll");
                //复制x64文件
                if (!File.Exists(x64FileName))
                {
                    if (!Directory.Exists(x64Path))
                    {
                        Directory.CreateDirectory(x64Path);
                    }
                    using (FileStream x64Stream = new FileStream(x64FileName, FileMode.Create))
                    {
                        byte[] buffer = Sql.SQLite.Resource1.SQLite_Interopx64;
                        x64Stream.Write(buffer, 0, buffer.Length);
                    }
                }
                //    // Adds an ACL entry on the specified directory for the specified account.
                //public static void AddDirectorySecurity(string FileName, string Account, FileSystemRights Rights, AccessControlType ControlType)
                //{
                //    // Create a new DirectoryInfo object.
                //    DirectoryInfo dInfo = new DirectoryInfo(FileName);

                //    // Get a DirectorySecurity object that represents the 
                //    // current security settings.
                //    DirectorySecurity dSecurity = dInfo.GetAccessControl();

                //    // Add the FileSystemAccessRule to the security settings. 
                //    dSecurity.AddAccessRule(new FileSystemAccessRule(Account,
                //                                                    Rights,
                //                                                    ControlType));

                //    // Set the new access settings.
                //    dInfo.SetAccessControl(dSecurity);

                //}
                //复制x86文件
                if (!File.Exists(x86FileName))
                {
                    if (!Directory.Exists(x86Path))
                    {
                        Directory.CreateDirectory(x86Path);
                    }
                    using (FileStream x86Stream = new FileStream(x86FileName, FileMode.Create))
                    {
                        byte[] buffer = Sql.SQLite.Resource1.SQLite_Interopx86;
                        x86Stream.Write(buffer, 0, buffer.Length);
                    }
                }
                return true;
            }
            catch(Exception ex)
            {
                return false;
            }
        }
    }
}
